import { useState } from 'react';
export function useTable(requestFn, options = {}) {
  const [tableData, setTableData] = useState([]);
  const [rowSelect, setRowSelect] = useState([]);
  const [pagination, setPagination] = useState({
    pageSize: 10,
    current: 1,
    showTotal: (total) => `共${total}条` /*总条数的展示*/,
  });
  async function _getData(param, sorter, filter) {
    try {
      const { data, total, current, pageSize, code } = await requestFn({
        ...param,
      });
      setPagination({ ...pagination, current: data?.current });
      return {
        data,
        success: code,
        total,
        current,
        pageSize,
      };
    } catch (error) {
      console.log('error===>', error);
    }
  }
  function _rowSelection(_, selectedRows) {
    setRowSelect(selectedRows);
  }

  return {
    tableData,
    _getData,
    pagination,
    rowSelect,
    _rowSelection,
  };
}
